import React, {Component} from 'react';

import './index.less';

import {base} from 'nc-lightapp-front';

const {NCButtonGroup, NCButton} = base;

class ShowType extends Component {
    constructor(props) {
        super(props);
    }

    onChange(type) {
        if (this.props.treeType === type) return;
        const {pageInfo} = this.props;
        this.props.updateState({
            treeType: type,
            currentSelectTreeNode: '',
            pageInfo: {
                ...pageInfo,
                pageIndex: 1
            }
        }, () => {
            this.props.hasSearched && this.props.getMainTableData()
        })
    }

    render() {
        const {
            treeType
        } = this.props;

        const showType = [
            {
                key: 'adminOrg',
                text: this.props.json['hi6007-000096']/* 国际化处理： 行政组织*/
            },
            {
                key: 'psnType',
                text: this.props.json['hi6007-000065']/* 国际化处理： 人员类别*/
            }
        ];

        return (
            <div className='show-type'>
                <div className='title'> {this.props.json['hi6007-000063']}：</div>
                {/* 国际化处理： 展示方式*/}
                <NCButtonGroup>
                    {showType.map(item => {
                        return <NCButton colors={treeType === item.key ? "primary" : ""}
                                         key={item.key}
                                         onClick={() => this.onChange(item.key)}>{item.text}</NCButton>
                    })}
                </NCButtonGroup>
            </div>
        );
    }
}

export default ShowType;
